package com.ztgf.sms.api.cms.email;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sms.models.bo.EmailInfoBO;
import com.ztgf.sms.models.dto.email.EmailInfoDTO;
import com.ztgf.sms.models.service.IEmailInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: chenyu.wang
 * date: 2020-05-25 10:31
 * Description:
 */
@RestController
@RequestMapping("/cms/email")
@Slf4j
@Api(value = "EmailInfoController", tags = "邮件接口")
public class EmailInfoController {


    @DubboReference
    private IEmailInfoService emailInfoService;


    @PostMapping("/queryPageList")
    @ApiOperation(value = "邮件列表", notes = "邮件列表")
    public Result<Page<EmailInfoDTO>> queryPageList(EmailInfoBO emailInfoBO) {
        Wrapper<EmailInfoDTO> wrapper = new EntityWrapper<>();
        if (emailInfoBO.getShopId() != null) {
            wrapper.eq("shop_id", emailInfoBO.getShopId());
        }
        if (emailInfoBO.getEmail() != null) {
            wrapper.eq("email", emailInfoBO.getEmail());
        }
        Page<EmailInfoDTO> page = new Page<>(emailInfoBO.getPageNo(), emailInfoBO.getPageSize());
        page = emailInfoService.selectPage(page, wrapper);
        return new Result<>(page);
    }

}
